ICPC data

library(leaflet)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(readr)
library(sf)
## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
world <- st_read("data/world.shp")
## Reading layer `world' from data source 
##   `/home/brayand/Storage/School/from-data-to-knowledge-interpretation-visualization-presentation-course/Homework 10/data/world.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 197 features and 63 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -180 ymin: -55.8917 xmax: 180 ymax: 83.59961
## Geodetic CRS:  GCS_unknown
data <- read_csv("data/icpc-full.csv")
## Rows: 2562 Columns: 21
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (10): Host, City, Venue, University, Country, Team, Contestant 1, Conte...
## dbl   (6): Year, Rank, Score, Total, Score Percentage, Penalty
## lgl   (4): Gold, Silver, Bronze, Honorable
## date  (1): Date
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
host_counts <- data %>%
  group_by(Host) %>%
  summarise(Count = n()) %>%
  ungroup()

print(world)
## Simple feature collection with 197 features and 63 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -180 ymin: -55.8917 xmax: 180 ymax: 83.59961
## Geodetic CRS:  GCS_unknown
## First 10 features:
##    scalerank      featurecla labelrank           sovereignt sov_a3 adm0_dif
## 1          1 Admin-0 country         3          South Sudan    SDS        0
## 2          1 Admin-0 country         3          Afghanistan    AFG        0
## 3          1 Admin-0 country         3               Angola    AGO        0
## 4          1 Admin-0 country         6       United Kingdom    GB1        1
## 5          1 Admin-0 country         6              Albania    ALB        0
## 6          3 Admin-0 country         6              Andorra    AND        0
## 7          1 Admin-0 country         4 United Arab Emirates    ARE        0
## 8          1 Admin-0 country         2            Argentina    ARG        0
## 9          1 Admin-0 country         6              Armenia    ARM        0
## 10         1 Admin-0 country         6  Antigua and Barbuda    ATG        0
##    level              type                admin adm0_a3 geou_dif
## 1      2 Sovereign country          South Sudan     SDS        0
## 2      2 Sovereign country          Afghanistan     AFG        0
## 3      2 Sovereign country               Angola     AGO        0
## 4      2        Dependency             Anguilla     AIA        0
## 5      2 Sovereign country              Albania     ALB        0
## 6      2 Sovereign country              Andorra     AND        0
## 7      2 Sovereign country United Arab Emirates     ARE        0
## 8      2 Sovereign country            Argentina     ARG        0
## 9      2 Sovereign country              Armenia     ARM        0
## 10     2 Sovereign country  Antigua and Barbuda     ATG        0
##                 geounit gu_a3 su_dif              subunit su_a3 brk_diff
## 1           South Sudan   SDS      0          South Sudan   SDS        0
## 2           Afghanistan   AFG      0          Afghanistan   AFG        0
## 3                Angola   AGO      0               Angola   AGO        0
## 4              Anguilla   AIA      0             Anguilla   AIA        0
## 5               Albania   ALB      0              Albania   ALB        0
## 6               Andorra   AND      0              Andorra   AND        0
## 7  United Arab Emirates   ARE      0 United Arab Emirates   ARE        0
## 8             Argentina   ARG      0            Argentina   ARG        0
## 9               Armenia   ARM      0              Armenia   ARM        0
## 10  Antigua and Barbuda   ATG      0  Antigua and Barbuda   ATG        0
##                    name            name_long brk_a3             brk_name
## 1              S. Sudan          South Sudan    SDS             S. Sudan
## 2           Afghanistan          Afghanistan    AFG          Afghanistan
## 3                Angola               Angola    AGO               Angola
## 4              Anguilla             Anguilla    AIA             Anguilla
## 5               Albania              Albania    ALB              Albania
## 6               Andorra              Andorra    AND              Andorra
## 7  United Arab Emirates United Arab Emirates    ARE United Arab Emirates
## 8             Argentina            Argentina    ARG            Argentina
## 9               Armenia              Armenia    ARM              Armenia
## 10    Antigua and Barb.  Antigua and Barbuda    ATG    Antigua and Barb.
##    brk_group  abbrev postal                    formal_en formal_fr note_adm0
## 1       <NA> S. Sud.     SS      Republic of South Sudan      <NA>      <NA>
## 2       <NA>    Afg.     AF Islamic State of Afghanistan      <NA>      <NA>
## 3       <NA>    Ang.     AO  People's Republic of Angola      <NA>      <NA>
## 4       <NA>    Ang.     AI                         <NA>      <NA>      U.K.
## 5       <NA>    Alb.     AL          Republic of Albania      <NA>      <NA>
## 6       <NA>    And.    AND      Principality of Andorra      <NA>      <NA>
## 7       <NA>  U.A.E.     AE         United Arab Emirates      <NA>      <NA>
## 8       <NA>    Arg.     AR           Argentine Republic      <NA>      <NA>
## 9       <NA>    Arm.    ARM          Republic of Armenia      <NA>      <NA>
## 10      <NA>  Ant.B.     AG          Antigua and Barbuda      <NA>      <NA>
##    note_brk            name_sort name_alt mapcolor7 mapcolor8 mapcolor9
## 1      <NA>          South Sudan     <NA>         1         3         3
## 2      <NA>          Afghanistan     <NA>         5         6         8
## 3      <NA>               Angola     <NA>         3         2         6
## 4      <NA>             Anguilla     <NA>         6         6         6
## 5      <NA>              Albania     <NA>         1         4         1
## 6      <NA>              Andorra     <NA>         1         4         1
## 7      <NA> United Arab Emirates     <NA>         2         1         3
## 8      <NA>            Argentina     <NA>         3         1         3
## 9      <NA>              Armenia     <NA>         3         1         2
## 10     <NA>  Antigua and Barbuda     <NA>         2         2         5
##    mapcolor13  pop_est gdp_md_est pop_year lastcensus gdp_year
## 1           5 10625176    13227.0       NA       2008       NA
## 2           7 28400000    22270.0       NA       1979       NA
## 3           1 12799293   110300.0       NA       1970       NA
## 4           3    14436      108.9       NA         NA       NA
## 5           6  3639453    21810.0       NA       2001       NA
## 6           8    83888     3660.0       NA       1989       NA
## 7           3  4798491   184300.0       NA       2010       NA
## 8          13 40913584   573900.0       NA       2010       NA
## 9          10  2967004    18770.0       NA       2001       NA
## 10          5    85632     1657.0       NA       2011       NA
##                       economy              income_grp wikipedia fips_10 iso_a2
## 1   7. Least developed region           5. Low income        NA    <NA>     SS
## 2   7. Least developed region           5. Low income        NA    <NA>     AF
## 3   7. Least developed region  3. Upper middle income        NA    <NA>     AO
## 4        6. Developing region  3. Upper middle income        NA    <NA>     AI
## 5        6. Developing region  4. Lower middle income        NA    <NA>     AL
## 6  2. Developed region: nonG7 2. High income: nonOECD        NA    <NA>     AD
## 7        6. Developing region 2. High income: nonOECD        NA    <NA>     AE
## 8     5. Emerging region: G20  3. Upper middle income        NA    <NA>     AR
## 9        6. Developing region  4. Lower middle income        NA    <NA>     AM
## 10       6. Developing region  3. Upper middle income        NA    <NA>     AG
##    iso_a3 iso_n3 un_a3 wb_a2 wb_a3 woe_id adm0_a3_is adm0_a3_us adm0_a3_un
## 1     SSD    728   728    SS   SSD     NA        SSD        SDS         NA
## 2     AFG    004   004    AF   AFG     NA        AFG        AFG         NA
## 3     AGO    024   024    AO   AGO     NA        AGO        AGO         NA
## 4     AIA    660   660  <NA>  <NA>     NA        AIA        AIA         NA
## 5     ALB    008   008    AL   ALB     NA        ALB        ALB         NA
## 6     AND    020   020    AD   ADO     NA        AND        AND         NA
## 7     ARE    784   784    AE   ARE     NA        ARE        ARE         NA
## 8     ARG    032   032    AR   ARG     NA        ARG        ARG         NA
## 9     ARM    051   051    AM   ARM     NA        ARM        ARM         NA
## 10    ATG    028   028    AG   ATG     NA        ATG        ATG         NA
##    adm0_a3_wb     continent region_un       subregion
## 1          NA        Africa    Africa  Eastern Africa
## 2          NA          Asia      Asia   Southern Asia
## 3          NA        Africa    Africa   Middle Africa
## 4          NA North America  Americas       Caribbean
## 5          NA        Europe    Europe Southern Europe
## 6          NA        Europe    Europe Southern Europe
## 7          NA          Asia      Asia    Western Asia
## 8          NA South America  Americas   South America
## 9          NA          Asia      Asia    Western Asia
## 10         NA North America  Americas       Caribbean
##                     region_wb name_len long_len abbrev_len tiny homepart
## 1          Sub-Saharan Africa        8       11          7   NA        1
## 2                  South Asia       11       11          4   NA        1
## 3          Sub-Saharan Africa        6        6          4   NA        1
## 4   Latin America & Caribbean        8        8          4   NA       NA
## 5       Europe & Central Asia        7        7          4   NA        1
## 6       Europe & Central Asia        7        7          4    5        1
## 7  Middle East & North Africa       20       20          6   NA        1
## 8   Latin America & Caribbean        9        9          4   NA        1
## 9       Europe & Central Asia        7        7          4   NA        1
## 10  Latin America & Caribbean       17       19          6    4        1
##                          geometry
## 1  MULTIPOLYGON (((33.95918 9....
## 2  MULTIPOLYGON (((74.89131 37...
## 3  MULTIPOLYGON (((14.19082 -5...
## 4  MULTIPOLYGON (((-63.00122 1...
## 5  MULTIPOLYGON (((20.06396 42...
## 6  MULTIPOLYGON (((1.706055 42...
## 7  MULTIPOLYGON (((53.92783 24...
## 8  MULTIPOLYGON (((-64.54917 -...
## 9  MULTIPOLYGON (((45.55234 40...
## 10 MULTIPOLYGON (((-61.71606 1...
world <- world %>%
  left_join(host_counts, by = c("name_long" = "Host"))

world$Count[is.na(world$Count)] <- 0

pal <- colorNumeric("YlOrRd", domain = world$Count)

leaflet(data = world) %>%
  addTiles() %>%
  addPolygons(
    fillColor = ~pal(Count),
    weight = 1,
    opacity = 1,
    color = "white",
    dashArray = "3",
    fillOpacity = 0.7,
    highlight = highlightOptions(
      weight = 3,
      color = "#666",
      dashArray = "",
      fillOpacity = 0.7,
      bringToFront = TRUE
    ),
    label = ~paste(name_long, ": ", Count, " times hosted"),
    labelOptions = labelOptions(
      style = list("font-weight" = "normal", padding = "3px 8px"),
      textsize = "15px",
      direction = "auto"
    )
  ) %>%
  addLegend(
    pal = pal,
    values = ~Count,
    opacity = 0.7,
    title = "Times Hosted",
    position = "bottomright"
  )